﻿using System.IO;
using System.Net;
using System.Text;
using StockAccessors.Interdin.Model;
using Utils;
using Utils.Extensions;

namespace StockAccessors.Interdin.Engine
{
	internal class DetailsPageReader
	{
		#region Properties

		public CookieContainer Cookies { get; set; }

		#endregion

		#region Public Methods

		public DetailsPage ReadPage(DetailsLink link)
		{
			using (HttpWebResponse response = HttpWebRequest2.SendGETRequest(link.GetLinkUrl(), Properties.Settings.Default.UserAgent, this.Cookies, Properties.Settings.Default.ReadTimeout))
			{
				using (Stream webStream = response.GetResponseStream())
				{
					return new DetailsPage(webStream.ReadTextResponse(response.CharacterSet));
				}
			}
		}

		#endregion
	}
}
